home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / utility / blrmu13.zip / NEWBLUZ.ASM < prev    next >
Assembly Source File  |  1990-09-21  |  10KB  |  378 lines

  1. page ,132
  2. title newbluz ( blues # 2 ) as of 09-21-90  02:45 am
  3. ;
  4. ;   read through arrays of tones and times using timer channel 2
  5. ;
  6. ;   Program originally
  7. ;   from p. 109 - PC Resource May 1987 ( hardin brothers )
  8. ;
  9. ;*-------------------------------------------------
  10. ;*  ( minor modifications by bud rasmussen )
  11. ;*  ( tune by bud rasmussen )
  12. ;*-------------------------------------------------
  13. ;
  14. code     segment
  15. ;
  16.          assume cs:code,ds:code
  17. ;
  18.          org   256
  19. ;
  20. newbluz:
  21. ;
  22.          jmp   play
  23. ;
  24. ppipb    equ   61h                     ; PPI port b
  25. tccr     equ   43h                     ; timer chip cmd reg
  26. tc2      equ   42h                     ; timer channel 2
  27. ;
  28. ;    This is the tone table -- the calculation formula is:
  29. ;    tone value = int ((1193180 / frequency) +.5)
  30. ;
  31. tones:
  32. ;
  33.          dw    9122                    ; c    1   ( c below middle c )
  34.          dw    8609                    ; c#   2
  35.          dw    8128                    ; d    3
  36.          dw    7668                    ; d#   4
  37.          dw    7240                    ; e    5
  38.          dw    6834                    ; f    6
  39.          dw    6450                    ; f#   7
  40.          dw    6088                    ; g    8
  41.          dw    5745                    ; g#   9
  42.          dw    5424                    ; a    10
  43.          dw    5119                    ; a#   11
  44.          dw    4833                    ; b    12
  45. ;
  46.          dw    4559                    ; c    13  ( middle c )
  47.          dw    4304                    ; c#   14
  48.          dw    4063                    ; d    15
  49.          dw    3835                    ; d#   16
  50.          dw    3620                    ; e    17
  51.          dw    3417                    ; f    18
  52.          dw    3225                    ; f#   19
  53.          dw    3044                    ; g    20
  54.          dw    2873                    ; g#   21
  55.          dw    2712                    ; a    22
  56.          dw    2559                    ; a#   23
  57.          dw    2416                    ; b    24
  58. ;
  59.          dw    2280                    ; c    25  ( c above middle c )
  60.          dw    2152                    ; c#   26
  61.          dw    2031                    ; d    27
  62.          dw    1917                    ; d#   28
  63.          dw    1810                    ; e    29
  64.          dw    1708                    ; f    30
  65.          dw    1612                    ; f#   31
  66.          dw    1522                    ; g    32
  67.          dw    1436                    ; g#   33
  68.          dw    1356                    ; a    34
  69.          dw    1279                    ; a#   35
  70.          dw    1208                    ; b    36
  71. ;
  72. ;
  73. ;*----------------
  74. ;*   tune table
  75. ;*----------------
  76. ;
  77. ;    This is the tune to be played.  The numbers are
  78. ;    indexes into the tone table above.
  79. ;
  80. ;    The list is terminated with a -1.
  81. ;
  82. ;    to make a rest:
  83. ;    use tone of 0 in tune table and length in time table
  84. ;
  85. ;
  86. tune:
  87. ;   bar 1
  88.          db    26
  89.          db    0
  90.          db    18
  91.          db    21
  92.          db    23
  93.          db    18
  94.          db    21
  95.          db    23
  96. ;   bar 2
  97.          db    26
  98.          db    18
  99.          db    21
  100.          db    23
  101. ;   bar 3
  102.          db    26
  103.          db    0
  104.          db    18
  105.          db    21
  106.          db    23
  107.          db    18
  108.          db    21
  109.          db    23
  110. ;   bar 4
  111.          db    26
  112.          db    18
  113.          db    24
  114.          db    0
  115. ;   bar 5
  116.          db    26
  117.          db    0
  118.          db    26
  119.          db    29
  120.          db    31
  121.          db    26
  122.          db    29
  123.          db    31
  124. ;   bar 6
  125.          db    33
  126.          db    33
  127.          db    31
  128.          db    31
  129.          db    29
  130. ;   bar 7
  131.          db    26
  132.          db    0
  133.          db    18
  134.          db    21
  135.          db    23
  136.          db    18
  137.          db    21
  138.          db    23
  139. ;   bar 8
  140.          db    24
  141.          db    0
  142.          db    26
  143.          db    26
  144.          db    26
  145. ;   bar 9
  146.          db    31
  147.          db    29
  148.          db    26
  149.          db    26
  150.          db    25
  151.          db    26
  152.          db    29
  153.          db    31
  154. ;   bar 10
  155.          db    32
  156.          db    31
  157.          db    29
  158.          db    26
  159.          db    26
  160. ;   bar 11
  161.          db    26
  162.          db    0
  163.          db    18
  164.          db    21
  165.          db    23
  166.          db    18
  167.          db    21
  168.          db    23
  169. ;   bar 12
  170.          db    24
  171.          db    0
  172. ;
  173.          db    -1                      ; end of tune table
  174. ;
  175. ;*----------------
  176. ;*   time table
  177. ;*----------------
  178. ;
  179. ;    Each entry in the time table corresponds to one of the
  180. ;    tones above.  Times are multiples of
  181. ;    the 18.2159 Hz heartbeat.
  182. ;
  183. ;    2 = eighth triplet
  184. ;    3 = eighth
  185. ;    4 = quarter triplet
  186. ;    6 = quarter
  187. ;   12 = half
  188. ;   24 = whole
  189. ;
  190. time:
  191. ;   bar 1
  192.          db    6
  193.          db    3
  194.          db    3
  195.          db    2
  196.          db    2
  197.          db    2
  198.          db    3
  199.          db    3
  200. ;   bar 2
  201.          db    3
  202.          db    6
  203.          db    6
  204.          db    9
  205. ;   bar 3
  206.          db    6
  207.          db    3
  208.          db    3
  209.          db    2
  210.          db    2
  211.          db    2
  212.          db    3
  213.          db    3
  214. ;   bar 4
  215.          db    3
  216.          db    6 
  217.          db    6
  218.          db    9
  219. ;   bar 5
  220.          db    6
  221.          db    3
  222.          db    3
  223.          db    2
  224.          db    2
  225.          db    2
  226.          db    3
  227.          db    3
  228. ;   bar 6
  229.          db    3
  230.          db    6
  231.          db    6
  232.          db    3
  233.          db    6
  234. ;   bar 7
  235.          db    6
  236.          db    3
  237.          db    3
  238.          db    2
  239.          db    2
  240.          db    2
  241.          db    3
  242.          db    3
  243. ;   bar 8
  244.          db    12
  245.          db    3
  246.          db    3
  247.          db    3
  248.          db    3
  249. ;   bar 9
  250.          db    3
  251.          db    3
  252.          db    3
  253.          db    6
  254.          db    3
  255.          db    2
  256.          db    2
  257.          db    2
  258. ;   bar 10
  259.          db    3
  260.          db    3
  261.          db    3
  262.          db    12
  263.          db    3
  264. ;   bar 11
  265.          db    6
  266.          db    3
  267.          db    3
  268.          db    2
  269.          db    2
  270.          db    2
  271.          db    3
  272.          db    3
  273. ;   bar 12
  274.          db    12
  275.          db    12
  276. ;
  277.          db    -1                      ; end of time table
  278. ;
  279. ;*------------------------------
  280. ;*   start of program
  281. ;*------------------------------
  282. ;
  283. play:
  284.          mov   bx,1                    ; synchronize with the timer ticks
  285.          call  delay                   ; by waiting for next one
  286.          in    al,ppipb                ; get current port status
  287.          or    al,3                    ; turn on lo 2 bits
  288.          out   ppipb,al                ; open gate to timer
  289.          mov   bx,0                    ; tone count
  290.          lea   di,time                 ; point to time table
  291. ;
  292. ;   music loop
  293. ;
  294. ml:
  295.          lea   si,tune                 ; point to tune table
  296.          mov   al,[si][bx]             ; get tone
  297.          mov   dl,[di][bx]             ; get duration
  298.          mov   dh,0                    ; clear duration word
  299.          cmp   al,-1                   ; end ?
  300.          je    done                    ; if so, get out
  301.          push  bx                      ; save count
  302.          test  al,al                   ; rest ?
  303.          jne   norest                  ; if not, carry on
  304.          mov   bx,dx                   ; move duration
  305.          call  rest                    ; turn speaker off
  306.          jmp   repeat                  ; goto repeat
  307. ;
  308. norest:
  309.          cbw                           ; make tone a word
  310.          dec   ax                      ; offset ftom 0
  311.          shl   ax,1                    ; * 2 to index word table
  312.          mov   bx,ax                   ; move to bx
  313.          lea   si,tones                ; point to tone table
  314.          mov   cx,[si][bx]             ; get the tone
  315.          call  maketone                ; turn speaker on
  316.          mov   bx,dx                   ; move duration
  317.          call  delay                   ; wait while it plays
  318. ;
  319. repeat:
  320.          mov   bx,0                    ; break between tones
  321.          call  rest                    ; turn spekaer off
  322.          pop   bx                      ; retrieve count
  323.          inc   bx                      ; + 1
  324.          jmp   ml                      ; loop
  325. ;
  326. ;*-------------------------
  327. ;*  sub routines
  328. ;*-------------------------
  329. ;
  330. ;   Enter maketone with frequency in cx
  331. ;   This routine starts the speaker going
  332. ;   Uses: AX
  333. ;
  334. maketone:
  335.          mov   al,10110110b            ; set up timer for ch 2
  336.          out   tccr,al                 ; timer chip ready for count
  337.          mov   al,cl                   ; get lsb of tone
  338.          out   tc2,al                  ; send to timer
  339.          mov   al,ch                   ; get msb of tone
  340.          out   tc2,al                  ; now tone has started
  341.          ret
  342. ;
  343. ;     Enter delay with delay count in bx
  344. ;     This routine will pause for bx / 18.2 seconds
  345. ;     Uses: AX, CX, DX
  346. ;
  347. delay:
  348.          mov   ah,0                    ; timer function - get time count
  349.          int   26                      ; timer count in cx:dx
  350.          add   bx,dx                   ; add to delay count
  351. delayl:
  352.          int   26                      ; get new timer count
  353.          cmp   bx,dx                   ; thru ?
  354.          jne   delayl                  ; if not, carry on
  355.          ret
  356. ;
  357. ;     Enter rest routine with count in BX
  358. ;
  359. rest:
  360.          in    al,ppipb                ; get current port status
  361.          push  ax                      ; save status
  362.          and   al,11111100b            ; turn off 2 lo bits
  363.          out   ppipb,al                ; send out
  364.          call  delay                   ; now wait
  365.          pop   ax                      ; get back value
  366.          out   ppipb,al                ; turn speaker on
  367.          ret
  368. ;
  369. done:
  370.          in    al,ppipb                ; get port status
  371.          and   al,11111100b            ; turn off 2 lo bits
  372.          out   ppipb,al                ; send it out
  373.          int   32                      ; get out
  374. ;
  375. code     ends
  376. ;
  377.          end   newbluz
  378.